home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2004 April / Gamestar_61_2004-04_dvdb.iso / DVDStar / Editace / hltp.exe / {app} / Applications / QuArK / plugins / map3views2Dlayout.py < prev    next >
Text File  |  2004-01-05  |  8KB  |  283 lines

  1. """   QuArK  -  Quake Army Knife
  2.  
  3. Modified Plug-in which define the Classical screen layout.
  4. """
  5. #
  6. # Copyright (C) 1996-99 Armin Rigo
  7. # THIS FILE IS PROTECTED BY THE GNU GENERAL PUBLIC LICENCE
  8. # FOUND IN FILE "COPYING.TXT"
  9. #
  10.  
  11. #$Header: /cvsroot/quark/runtime/plugins/map3views2Dlayout.py,v 1.2 2003/03/24 05:09:51 cdunde Exp $
  12.  
  13. ### Nurail - Mar 22, 2003 - Modification of map3viewslayout for 2D only views.
  14.  
  15.  
  16. Info = {
  17.    "plug-in":       "3-Views 2D Layout",
  18.    "desc":          "QuArK's 3-views Screen Layout.",
  19.    "date":          "22 March 2003",
  20.    "author":        "Nurail/Armin Rigo",
  21.    "author e-mail": "nurail@yahoo.com",
  22.    "quark":         "Version 6.3" }
  23.  
  24.  
  25. from quarkpy.mapmgr import *
  26.  
  27.  
  28. #
  29. # The 3-views Layout is implemented as a subclass of the base class MapLayout.
  30. #
  31.  
  32. class ThreeViews2DLayout(MapLayout):
  33.     "The 3-views QuArK layout with only 2D windows."
  34.  
  35.     shortname = "3 views (2D)"
  36.  
  37.     def buildscreen(self, form):
  38.  
  39.         #
  40.         # We put the standard left panel first.
  41.         #
  42.  
  43.         self.bs_leftpanel(form)
  44.  
  45.         #
  46.         # Divide the main panel into two sections.
  47.         # horizontally, 1 section;
  48.         # vertically, 2 sections split at 40% of the height
  49.         #  (use "-0.4" instead of "0.4" to disable user resizing)
  50.         #
  51.  
  52.         form.mainpanel.sections = ((), (0.4,))
  53.  
  54.         #
  55.         # Create the XY view in the section (0,1), i.e. down.
  56.         #
  57.  
  58.         self.ViewXY = form.mainpanel.newmapview()
  59.         self.ViewXY.section = (0,1)
  60.  
  61.         #
  62.         # Create a panel in the top section.
  63.         #
  64.  
  65.         self.threeviews_toppanel = form.mainpanel.newpanel()
  66.         self.threeviews_toppanel.sections = ((0.65,), ())
  67.  
  68.         #
  69.         # Create the XZ and YZ views
  70.         #
  71.  
  72.         self.ViewXZ = self.threeviews_toppanel.newmapview()
  73.         self.ViewYZ = self.threeviews_toppanel.newmapview()
  74.         self.ViewYZ.section = (1,0)
  75.     
  76.         #
  77.         # Put these three views in the view lists.
  78.         #
  79.  
  80.         self.views[:] = [self.ViewXY, self.ViewXZ, self.ViewYZ]
  81.         self.baseviews = self.views[:]
  82.  
  83.         #
  84.         # Setup initial display parameters.
  85.         #
  86.  
  87.         scale = 0.25   # default value
  88.  
  89.         self.ViewXY.info = {
  90.           "type": "XY",     # XY view
  91.           "angle": 0.0,     # compass angle
  92.           "scale": scale,   # scale
  93.           "vangle": 0.0}    # vertical angle
  94.  
  95.         self.ViewXZ.info = {
  96.           "type": "XZ",     # XZ view
  97.           "angle": 0.0,
  98.           "scale": scale,
  99.           "vangle": 0.0}
  100.  
  101.         self.ViewYZ.info = {
  102.           "type": "YZ",     # YZ view
  103.           "angle": 0.0,
  104.           "scale": scale,
  105.           "vangle": 0.0}
  106.  
  107.         #
  108.         # Link the horizontal position of the XZ view to that of the
  109.         # XY view, and remove the horizontal scroll bar of the XZ view.
  110.         #
  111.  
  112.         self.sblinks.append((0, self.ViewXY, 0, self.ViewXZ))
  113.         self.sblinks.append((1, self.ViewYZ, 1, self.ViewXZ))
  114.         self.sblinks.append((1, self.ViewXY, 0, self.ViewYZ))
  115.         self.ViewXZ.flags = self.ViewXZ.flags &~ (MV_HSCROLLBAR | MV_VSCROLLBAR)
  116.         
  117.  
  118.     #
  119.     # The following function is called when the configuration changed.
  120.     # We show or hide the red lines here.
  121.     #
  122.  
  123.     def setupchanged(self, level):
  124.  
  125.         #
  126.         # First call the inherited "setupchanged".
  127.         #
  128.  
  129.         MapLayout.setupchanged(self, level)
  130.  
  131.  
  132.         #
  133.         # Read the old flags and set both red lines by default.
  134.         #
  135.  
  136.         flagsXY = self.ViewXY.flags | MV_TOPREDLINE | MV_BOTTOMREDLINE
  137.         flagsXZ = self.ViewXZ.flags | MV_TOPREDLINE | MV_BOTTOMREDLINE
  138.         flagsYZ = self.ViewYZ.flags | MV_TOPREDLINE | MV_BOTTOMREDLINE
  139.  
  140.         #
  141.         # Remove the 2nd red line if required.
  142.         #
  143.  
  144.         if not MapOption("RedLines2"):
  145.             flagsXY = flagsXY &~ MV_TOPREDLINE
  146.             flagsXZ = flagsXZ &~ MV_BOTTOMREDLINE
  147.             flagsYZ = flagsYZ &~ MV_BOTTOMREDLINE
  148.  
  149.         #
  150.         # Update the flags.
  151.         #
  152.  
  153.         self.ViewXY.flags = flagsXY
  154.         self.ViewXZ.flags = flagsXZ
  155.         self.ViewYZ.flags = flagsYZ
  156.  
  157.  
  158.  
  159.     #
  160.     # The following function is called to compute the limits of
  161.     # the visible (non-grayed-out) areas for each map view.
  162.     #
  163.  
  164.     def setupdepth(self, view):
  165.  
  166.         #
  167.         # First check the "view" parameter.
  168.         #
  169.  
  170.         if not (view in (self.ViewXY, self.ViewXZ, self.ViewYZ)):
  171.             return
  172.  
  173.         #
  174.         # To compute the visible areas for the XY view, we
  175.         # get the rectangular area (in pixels) of the XZ view.
  176.         #
  177.  
  178.         x1,y1,x2,y2 = self.ViewXZ.redlinesrect
  179.  
  180.         #
  181.         # The line below does this :
  182.         #  * take a corner of the above rectangle
  183.         #  * compute the 3D coordinates of any point above this corner
  184.         # This gives a 3D point that is at the top limit of the visible area for the XY view.
  185.         #  * project this 3D point on the XY view
  186.         #  * keep only the z coordinate (i.e. the depth) of this projection
  187.         # This gives the depth of the top limit, which is what we wanted.
  188.         #
  189.         # The second line does the same for the other corner, which gives
  190.         # the bottom limit of the visible area.
  191.         #
  192.  
  193.         xydepth = (self.ViewXY.proj(self.ViewXZ.space(x1, y1, 0.0)).z,
  194.                    self.ViewXY.proj(self.ViewXZ.space(x2, y2, 0.0)).z)
  195.  
  196.         #
  197.         # Do it again for the XZ view...
  198.         #
  199.  
  200.         x1,y1,x2,y2 = self.ViewXY.redlinesrect
  201.         corner1 = self.ViewXY.space(x1, y1, 0.0)
  202.         corner2 = self.ViewXY.space(x2, y2, 0.0)
  203.         
  204.         xzdepth = (self.ViewXZ.proj(corner2).z,
  205.                    self.ViewXZ.proj(corner1).z)
  206.  
  207.         #
  208.         # Do it again for the YZ view...
  209.         #
  210.  
  211.         yzdepth = (self.ViewYZ.proj(corner1).z,
  212.                    self.ViewYZ.proj(corner2).z)
  213.  
  214.         #
  215.         # Depending on the draw mode, items may or may not be grayed
  216.         # out. If they are, we must redraw a view when the other one
  217.         # is scrolled, in case objects came in or out of view. This
  218.         # is done by calling "setdepth". Otherwise, we directly set
  219.         # the map view's "depth" attribute, which doesn't redraw the
  220.         # view.
  221.         #
  222.  
  223.         redraw = self.editor.drawmode & DM_MASKOOV
  224.  
  225.         if redraw and (view is not self.ViewXY):
  226.             self.ViewXY.setdepth(xydepth)
  227.         else:
  228.             self.ViewXY.depth = xydepth
  229.  
  230.         if redraw and (view is not self.ViewXZ):
  231.             self.ViewXZ.setdepth(xzdepth)
  232.         else:
  233.             self.ViewXZ.depth = xzdepth
  234.  
  235.         if redraw and (view is not self.ViewYZ):
  236.             self.ViewYZ.setdepth(yzdepth)
  237.         else:
  238.             self.ViewYZ.depth = yzdepth
  239.  
  240.  
  241.     #
  242.     # Functions to read and store the layout (window positions,...)
  243.     # in the Setup.
  244.     #
  245.  
  246.     def readconfig(self, config):
  247.         MapLayout.readconfig(self, config)
  248.         vsec = config["hvsec"]
  249.         if type(vsec)==type(()) and len(vsec)==2:
  250.             self.editor.form.mainpanel.sections = ((), vsec[:1])
  251.             self.threeviews_toppanel.sections = (vsec[1:], ())
  252.  
  253.     def writeconfig(self, config):
  254.         MapLayout.writeconfig(self, config)
  255.         hsec, vsec = self.editor.form.mainpanel.sections
  256.         hsec2, vsec2 = self.threeviews_toppanel.sections
  257.         config["hvsec"] = vsec + hsec2
  258.  
  259.  
  260.  
  261. #
  262. # Register the new layout.
  263. #
  264.  
  265. LayoutsList.append(ThreeViews2DLayout)
  266.  
  267.  
  268. # ----------- REVISION HISTORY ------------
  269. #
  270. #
  271. # $Log: map3views2Dlayout.py,v $
  272. # Revision 1.2  2003/03/24 05:09:51  cdunde
  273. # To upload the "new and improved" version of the layout. The layout
  274. # itself seems to work fine, but somewhere in the python code, the
  275. # auto-centering code might need some work. The views should center on
  276. # the center of the view being moved, but that's not the case.
  277. #
  278. # Revision 1.1  2003/03/24 05:02:48  cdunde
  279. # To add new 3 view - 2D layout
  280. #
  281.